<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/EditableItem.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/RangeMenu.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GridFilters.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/Filter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
        <script type="text/javascript">
            var pMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.procurement');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
            
            var ctYesno = new i18nMessage('../../servlet/CodeTableServlet?name=CtYesno');
            
            var store;
            var grid;
            
            var deleteCallback = function(btn){
                if (btn == 'yes') {
                    Ext.Ajax.request({
                        url: '../../servlet/ProcurementServlet?action=2&id=' + deleteId,
                        success: function(o){
                            if (o.responseText == 'success') {
                                store.reload();
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
                            }
                            else {
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
                            }
                        },
                        failure: function(o){
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
                        },
                        params: {
                            foo: 'bar'
                        }
                    });
                }
            }
            
            Ext.onReady(function(){
                Ext.QuickTips.init();
                Ext.form.Field.prototype.msgTarget = 'side';
                
                
                store = new Ext.data.Store({
                    url: '../../servlet/ProcurementServlet?action=4',
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, ['index', 'name', 'isFinished', 'createTime','comment', 'id']),
                    
                    remoteSort: true
                });
                
                store.setDefaultSort('id', 'desc');
                
                var filters = new Ext.grid.GridFilters({
                    filters: [{
                        type: 'string',
                        dataIndex: 'name'
                    }, {
                        type: 'list',
                        dataIndex: 'isFinished',
                        options: ctYesno.getCtArray()
                    }]
                });
                
                grid = new Ext.grid.GridPanel({
                    title: pMessage.get('ui.procurement.listtitle'),
                    store: store,
                    stripeRows: true,
                    plugins: filters,
                    height: 560,
                    columns: [{
                        header: message.get('message.list.id'),
                        width: 50,
                        dataIndex: 'index',
                        sortable: false
                    }, {
                        header: pMessage.get('ui.procurement.name'),
                        dataIndex: 'name',
                        sortable: true
                    }, {
                        header: pMessage.get('ui.procurement.isfinished'),
                        dataIndex: 'isFinished',
                        sortable: true,
						renderer: renderIsFinished
                    }, {
                        header: message.get('message.edit.createdate') + '(d/m/Y)',
                        dataIndex: 'createTime',
                        sortable: true
                    },{
                        header: pMessage.get('ui.procurement.yarn'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderProcurementYarn
                    },{
                        header: pMessage.get('ui.procurement.useryarn'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderUser
                    },{
                        header: pMessage.get('ui.procurement.button'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderButton
                    },{
                        header: pMessage.get('ui.procurement.zip'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderZip
                    },{
                        header: pMessage.get('ui.procurement.cardboard'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderCardboard
                    },{
                        header: pMessage.get('ui.procurement.accessory'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderAccessory
                    },{
                        header: pMessage.get('ui.procurement.order'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderOrder
                    },{
                        header: message.get('message.list.eidtitem'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderEditItem
                    },{
                        header: message.get('message.list.eidt'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderEdit
                    }, {
                        header: message.get('message.list.delete'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderDelete
                    }],
                    viewConfig: {
                        forceFit: true
                    },
                    loadMask: true,
                    renderTo: 'procurementList',
                    bbar: new Ext.PagingToolbar({
                        pageSize: 20,
                        store: store,
                        displayInfo: true
                    })
                });
                
                var startPage = getPrarmeterValue(window.location, 'startPage');
                var start;
                if (startPage == null || startPage == '') {
                    start = 0;
                }
                else {
                    start = (startPage - 1) * 20;
                }
                store.load({
                    params: {
                        start: start,
                        limit: 20
                    }
                });
				
				function renderProcurementYarn(value, p, record){
					return String.format('<a href="procurement_yarn_table.jsp?id={1}" target="_blank"><img ext:qtip="{0}" src="../../images/icons/shading.png" /></a>', pMessage.get('ui.procurement.yarn'), record.id);
				}
				
				function renderUser(value, p, record){
					return String.format('<a href="procurement_user_yarn_table.jsp?id={1}" target="_blank"><img ext:qtip="{0}" src="../../images/icons/report_user.png" /></a>', pMessage.get('ui.procurement.useryarn'), record.id);
				}
				
				function renderButton(value, p, record){
                    return String.format('<a href="procurement_button_table.jsp?id={1}" target="_blank"><img ext:qtip="{0}" src="../../images/icons/sport_golf.png" /></a>', pMessage.get('ui.procurement.button'), record.id);
				}
				
				function renderZip(value, p, record){
                    return String.format('<a href="procurement_zip_table.jsp?id={1}" target="_blank"><img ext:qtip="{0}" src="../../images/icons/link.png" /></a>', pMessage.get('ui.procurement.zip'), record.id);
				}
				
				function renderCardboard(value, p, record){
					return String.format('<a href="procurement_cardboard_table.jsp?id={1}" target="_blank"><img ext:qtip="{0}" src="../../images/icons/page.png" /></a>', pMessage.get('ui.procurement.cardboard'), record.id);
				}
				
				function renderAccessory(value, p, record){
                    return String.format('<a href="procurement_accessory_other_table.jsp?id={1}" target="_blank"><img  ext:qtip="{0}" src="../../images/icons/bricks.png"/></a>', pMessage.get('ui.procurement.accessory'), record.id);
				}
				
				function renderOrder(value, p, record){
					return String.format('<a href="procurement_order_table.jsp?id={1}" target="_blank"><img  ext:qtip="{0}" src="../../images/icons/application_view_tile.png"/></a>', pMessage.get('ui.procurement.order'), record.id);
				}
				
                function renderIsFinished(value, p, record){
					if(value == '02')
						return String.format('<img ext:qtip="{0}" src="../../images/icons/cross.png" />', message.get('message.list.no'));
					else
						return String.format('<img ext:qtip="{0}" src="../../images/icons/tick.png"/>', message.get('message.list.yes'));
                }
				
				function renderEditItem(value, p, record){
					return String.format('<a href="procurement_item_edit.html?id={0}&startPage={1}" target="_self"><img src="../../images/icons/sitemap_color.png" title="' + message.get('message.list.eidt') + message.get('message.list.eidtitem') + '" /></a>', record.id, Math.floor((record.data.index - 1) / 20) + 1);
				}
				
                function renderEdit(value, p, record){
                    return String.format('<a href="procurement_edit.html?id={0}&startPage={1}" target="_self"><img src="../../images/icons/pencil.png" title="' + message.get('message.list.eidt') + '" /></a>', record.id, Math.floor((record.data.index - 1) / 20) + 1);
                }
                
                function renderDelete(value, p, record){
                    return String.format('<a href="javascript: deleteItem(deleteCallback, {0});"><img src="../../images/icons/delete.png" title="' + message.get('message.list.delete') + '"/></a>', record.id);
                }
                
            });
        </script>
    </head>
    <body>
		<div id="procurementList"></div>
    </body>
</html>
